package com.cryann.mqttserver.modle;

import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttPublishMessage;
import lombok.Data;

import javax.persistence.*;
import java.util.Objects;
import java.util.Set;

/**
 * @author cRyann
 * @date 2018/12/6 0006 15:34
 * @description:
 */
@Data
@Entity
public class Accessor {

    @Id
    protected String identifier;

    protected String accessorName;

    protected String accessorIp;

    protected String channelId;

    protected Long activeTime;

    protected Boolean willFlag;

    @Transient
    protected MqttPublishMessage willMessage;

    protected Boolean cleanSession;

    protected Integer keepLive;

    protected Boolean onLine;

    @ElementCollection(fetch = FetchType.EAGER)
    protected Set<String> topicName;

    @Transient
    protected Channel channel;


    @Override
    public boolean equals(Object o) {
        if ( this == o ) return true;
        if ( o == null || getClass() != o.getClass() ) return false;
        Accessor accessor = (Accessor) o;
        return Objects.equals(identifier, accessor.identifier) &&
                Objects.equals(accessorName, accessor.accessorName) &&
                Objects.equals(accessorIp, accessor.accessorIp) &&
                Objects.equals(channelId, accessor.channelId) &&
                Objects.equals(activeTime, accessor.activeTime) &&
                Objects.equals(willFlag, accessor.willFlag) &&
                Objects.equals(cleanSession, accessor.cleanSession) &&
                Objects.equals(keepLive, accessor.keepLive) &&
                Objects.equals(onLine, accessor.onLine) &&
                Objects.equals(topicName, accessor.topicName) &&
                Objects.equals(channel, accessor.channel);
    }

    @Override
    public int hashCode() {
        return Objects.hash(identifier);
    }
}
